<?php

FLEA::loadClass('FLEA_Controller_Action');

class Controller_Admin_usergroup extends FLEA_Controller_Action
{

	/**
	 * $md_User
	 * @var Model_UserManager
	 */
	var $md_User;
	
	function Controller_Admin_usergroup()
	{
		$this->md_User =& FLEA::getSingleton('Model_UserManager');
	}
	
	function actionIndex()
	{
		redirect($this->_url('usergrouplist'));
	}
	
	function actionUserGroupList()
	{
				
		//组织数据
		$viewdata = array(
			'ugList' => $this->md_User->usergroupList(),
			'title' => '用户组管理',
			'menu_user_group' => 'id="current"',
	    );
	    
		$this->_executeView('admin/Websetup_usergroup.html', $viewdata);
		
	}
	
	//根据提交的POST数据更新指定的UserGroup数据
	function actionModifyUserGroup(){
		
		//dump($_POST);
		$this->md_User->saveUserGroup($_POST);
		
		redirect($this->_url('usergrouplist'));
		
	}

	//删除指定ID的UserGroup
	function actionremoveUserGroup(){
		
		if($this->md_User->removeUserGroup($_GET['id'])) {
			echo true;
		}else{
			echo false;
		}
		
	}
	
	//ajax返回不包含$get['id']树的tree
	function actionajaxTree(){
		if($this->_isAjax()){
			//返回去掉以ID为根的树
			echo json_encode($this->md_User->usergroupList($_GET['id']));
		}else {
			redirect($this->_url('index'));
		}
	}

	/**
	 * 用户组绑定角色和权限
	 */
	function actionband(){
		
		//组织数据
		$viewdata = array(
			'ugList' => $this->md_User->usergroupList(-1),
			'rolesList' => $this->md_User->rolesList(),
			'permissionsList' => $this->md_User->permissionsList(),
			'title' => '用户组角色/权限绑定',
			'menu_user_group' => 'id="current"',
	    );
		$this->_executeView('admin/Websetup_usergroupband.html', $viewdata);
	}
	
	/**
	 * ajax：获取一个用户组的继承权限
	 */
	function actiongetUgInherit(){
		if($this->_isAjax()){
			$acl =& FLEA::getSingleton('Model_AclManager');
			$user = $acl->getUgInherit($_GET['user_group_id']);
			echo json_encode($user);
		}else{
			redirect($this->_url('index'));
		}
	}

	/**
	 * 保存用户组绑定
	 */
	function actionsaveBand(){
		$acl =& FLEA::getSingleton('Model_AclManager');
		/*@var $acl Model_AclManager*/
		$acl->saveugBand($_POST);
		redirect($this->_url('band'));
	}

	
}

?>